/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:59 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class Khoahoc_BaihocDAL : SqlProvider<Khoahoc_BaihocEntity>
    {
        static Khoahoc_BaihocDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Khoahoc_BaihocEntity entity = new Khoahoc_BaihocEntity();
				entity.PK_iKhoahoc_BaihocID = Int64.Parse("0"+dr["PK_iKhoahoc_BaihocID"].ToString());
				entity.FK_iKhoahocID = Int64.Parse("0"+dr["FK_iKhoahocID"].ToString());
				entity.FK_iBaihocID = Int64.Parse("0"+dr["FK_iBaihocID"].ToString());
                entity.iSothutu = int.Parse("0" + dr["iSothutu"].ToString());
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static Khoahoc_BaihocEntity GetOne(Int64 PK_iKhoahoc_BaihocID)
        {
            string cmdName = "spKhoahoc_Baihoc_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iKhoahoc_BaihocID", PK_iKhoahoc_BaihocID);
            Khoahoc_BaihocEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Khoahoc_BaihocEntity> GetAll()
        {
            string cmdName = "spKhoahoc_Baihoc_Get";
            return GetList(cmdName);
        }
        public static List<Khoahoc_BaihocEntity> GetByFK_iKhoahocID(Int64 FK_iKhoahocID)
		{
			string cmdName = "spKhoahoc_Baihoc_GetByFK_FK_iKhoahocID";
			SqlParameter p = new SqlParameter("@FK_iKhoahocID",FK_iKhoahocID);
			List<Khoahoc_BaihocEntity> list = GetList(cmdName, p);
			return list;
		}public static List<Khoahoc_BaihocEntity> GetByFK_iBaihocID(Int64 FK_iBaihocID)
		{
			string cmdName = "spKhoahoc_Baihoc_GetByFK_FK_iBaihocID";
			SqlParameter p = new SqlParameter("@FK_iBaihocID",FK_iBaihocID);
			List<Khoahoc_BaihocEntity> list = GetList(cmdName, p);
			return list;
		}
        public static List<Khoahoc_BaihocEntity> GetByFK_iKhoahocIDAndFK_iBaihocID(Int64 FK_iKhoahocID, Int64 FK_iBaihocID)
        {
            string cmdName = "sp_Khoahoc_Baihoc_GetByFK_iKhoahocIDAndFK_iBaihocID";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iBaihocID", FK_iBaihocID);
            p[1] = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            List<Khoahoc_BaihocEntity> list = GetList(cmdName, p);
            return list;
        }
        public static int Add(Khoahoc_BaihocEntity entity)
        {
            string cmdName = "spKhoahoc_Baihoc_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(Khoahoc_BaihocEntity entity)
        {
            string cmdName = "spKhoahoc_Baihoc_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iKhoahoc_BaihocID)
        {
            string cmdName = "spKhoahoc_Baihoc_Delete";
            SqlParameter p = new SqlParameter("@PK_iKhoahoc_BaihocID", PK_iKhoahoc_BaihocID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Khoahoc_BaihocEntity entity)
        {
            SqlParameter[] p = new SqlParameter[5];
			p[0] = new SqlParameter("@PK_iKhoahoc_BaihocID", entity.PK_iKhoahoc_BaihocID);
			p[1] = new SqlParameter("@FK_iKhoahocID", entity.FK_iKhoahocID);
			p[2] = new SqlParameter("@FK_iBaihocID", entity.FK_iBaihocID);
            p[3] = new SqlParameter("@iSothutu", entity.iSothutu);
			p[4] = new SqlParameter("@sGhichu", entity.sGhichu);
            
            return p;
        }
        #endregion
       
    }
}